package com.neulogistics.contrib.procuredcenter.api.application.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neulogistics.contrib.procuredcenter.api.application.converter.GoodsSetPOVMConverter;
import com.neulogistics.contrib.procuredcenter.api.application.viewmodel.GoodsListViewModel;
import com.neulogistics.contrib.procuredcenter.api.application.viewmodel.GoodsSetViewModel;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.GoodsSetPO;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.service.IGoodsSetPOService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GoodsSetQueryService implements IGoodsSetQueryService {
    @Resource
    IGoodsSetPOService goodsSetPOService;

    @Override
    public GoodsSetViewModel getById(Integer setId) {
        GoodsSetPO goodsSetPO = goodsSetPOService.getById(setId);
        GoodsSetViewModel goodsSetViewModel = GoodsSetPOVMConverter.POToVM(goodsSetPO);

        return goodsSetViewModel;
    }

    @Override
    public List<GoodsSetViewModel> listByList(Integer listId) {
        LambdaQueryWrapper<GoodsSetPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GoodsSetPO::getListId, listId);

        List<GoodsSetPO> setPOList = goodsSetPOService.list(queryWrapper);
        List<GoodsSetViewModel> setViewModelList = setPOList.stream()
                .map(GoodsSetPOVMConverter::POToVM).collect(Collectors.toList());
        return setViewModelList;
    }

    @Override
    public List<GoodsSetViewModel> list() {
        List<GoodsSetPO> goodsSetPOList = goodsSetPOService.list();
        List<GoodsSetViewModel> viewModelList = goodsSetPOList.stream()
                .map(GoodsSetPOVMConverter::POToVM).collect(Collectors.toList());
        return viewModelList;
    }
}
